﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

namespace Journeo_backend.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [AllowAnonymous]
    public class TransportationPlanController : ControllerBase
    {
        private readonly ITransportationPlanService _transportationPlanService;

        public TransportationPlanController(ITransportationPlanService transportationPlanService)
        {
            _transportationPlanService = transportationPlanService;
        }

        [HttpPost("create")]
        [SwaggerOperation(Summary = "创建交通计划", Description = "创建交通计划")]
        [SwaggerResponse(200, "创建成功", typeof(Response<TransportationPlan>))]
        [SwaggerResponse(400, "创建失败")]
        public async Task<IActionResult> CreateTransportationPlan(TransportationPlanDTO transportationPlanDTO)
        {
            var response = await _transportationPlanService.CreateTransportationPlan(transportationPlanDTO);
            return Ok(response);
        }

        [HttpPut("update")]
        [SwaggerOperation(Summary = "更新交通计划", Description = "更新交通计划")]
        [SwaggerResponse(200, "更新成功", typeof(Response<TransportationPlan>))]
        [SwaggerResponse(400, "更新失败")]
        public async Task<IActionResult> UpdateTransportationPlan(long transportId, TransportationPlanDTO transportationPlanDTO)
        {
            var response = await _transportationPlanService.UpdateTransportationPlan(transportId, transportationPlanDTO);
            return Ok(response);
        }

        [HttpDelete("delete/{transportId}")]
        [SwaggerOperation(Summary = "根据Id删除交通计划", Description = "根据交通计划的Id删除交通计划")]
        [SwaggerResponse(200, "删除成功", typeof(Response<string>))]
        [SwaggerResponse(400, "删除失败")]
        public async Task<IActionResult> DeleteTransportationPlan(long transportId)
        {
            var response = await _transportationPlanService.DeleteTransportationPlan(transportId);
            return Ok(response);
        }

        [HttpDelete("delete/plan/{planId}")]
        [SwaggerOperation(Summary = "根据计划Id删除计划的所有交通计划", Description = "根据计划Id删除计划的所有交通计划")]
        [SwaggerResponse(200, "删除成功", typeof(Response<string>))]
        [SwaggerResponse(400, "删除失败")]
        public async Task<IActionResult> DeleteTransportationPlans(long planId)
        {
            var response = await _transportationPlanService.DeleteTransportationPlans(planId);
            return Ok(response);
        }

        [HttpGet("detail/{transportId}")]
        [SwaggerOperation(Summary = "根据Id获取交通计划详情", Description = "根据Id获取交通计划详情")]
        [SwaggerResponse(200, "获取成功", typeof(Response<TransportationPlan>))]
        [SwaggerResponse(400, "获取失败")]
        public async Task<IActionResult> GetTransportationPlan(long transportId)
        {
            var response = await _transportationPlanService.GetTransportationPlan(transportId);
            return Ok(response);
        }

        [HttpGet("plans/{planId}")]
        [SwaggerOperation(Summary = "根据计划Id获取计划的所有交通计划", Description = "根据计划Id获取计划的所有交通计划")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<TransportationPlan>))]
        [SwaggerResponse(400, "获取失败")]
        public async Task<IActionResult> GetTransportationPlans(long planId, int pageNumber, int pageSize)
        {
            var response = await _transportationPlanService.GetTransportationPlans(planId, pageNumber, pageSize);
            return Ok(response);
        }


    }
}
